package ru.sviridov.sellandbuy.tasks.recipients;

import ru.sviridov.sellandbuy.model.Response;
import ru.sviridov.sellandbuy.tasks.base.TaskRecipient;
import ru.sviridov.sellandbuy.tools.Constants;
import android.content.Context;
import android.widget.Toast;
import api.istsoft.ru.dal.Auth.Profile;

public class UpdateProfileRecipient implements TaskRecipient {

	@Override
	public void onURLError(Context context, int errorCode) {
		Toast.makeText(context, "server is unreachable", Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onJSONError(Context context, Response response) {
		Toast.makeText(context, response.getErrorMessage(), Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onSuccess(Context context, Response response) {
		if(context!=null)
			((Profile)response.getResults()[0]).store(context.getSharedPreferences(Constants.USER_PREFS, Context.MODE_PRIVATE).edit());
	}

}
